﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CommandTask.cs" company="JDML Consulting Ltd.">
//   Copyright 2011 Photon Project - http://photon.codeplex.com
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Photon.Threading
{
    using System;
    using System.ComponentModel;
    using EventPattern;

    public class CommandTask : Task
    {
        private readonly TestEventSource _source;

        public CommandTask(TestEventSource source, TaskScheduler scheduler) : base(scheduler)
        {
            _source = source;
        }

        public string Arg1 { get; set; }

        protected override ITaskBinding CreateBinding()
        {
            return AsyncEventTaskBinding.From(_source.DoNothing, Arg1);
        }
    }

    public class TestEventSource
    {
        public void DoNothing(string arg1, object userState)
        {
            if (DoNothingCompleted != null)
                DoNothingCompleted(this, new AsyncCompletedEventArgs(null, false, userState));
        }

        private event EventHandler<AsyncCompletedEventArgs> DoNothingCompleted;
    }
}